package com.dxy.hms.model.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

@Data
@Accessors(chain = true)
public class TreeVo {

    @ApiModelProperty("当前节点Id")
    private String id;

    @ApiModelProperty("当前节点展示文本")
    private String text;

    @ApiModelProperty("当前节点数据值")
    private Object val;

    @ApiModelProperty("父节点Id")
    private String parentId;

    @ApiModelProperty("当前节点排序号")
    private int sort;

    @ApiModelProperty("当前节点是否有子节点")
    private boolean hasChildren;

    @ApiModelProperty("子节点列表")
    private List<TreeVo> childList = new ArrayList<>();

    // 是否可见节点（辅助计算用）
    @JsonIgnore
    @JSONField(serialize = false)
    private boolean visible = true;

    // 添加子节点
    public void addChild(TreeVo treeVo){
        this.hasChildren = true;
        childList.add(treeVo);
    }

}
